refactor: extract _check_open_perms, fix dead elsif in sysopen#353
Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Draft
refactor: extract _check_open_perms, fix dead elsif in sysopen#353Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Conversation
The open/sysopen permission-check block was copy-pasted three times (in __open, _io_file_mock_open, and __sysopen) with subtle divergences. In __sysopen, the elsif branch checking parent-dir perms was dead code: contents was always defined at that point because the ENOENT check above already returned. This meant sysopen(FH, $path, O_WRONLY|O_CREAT) in a restricted parent directory silently succeeded — inconsistent with open(). Fix: capture $is_new before O_CREAT populates contents, extract a shared _check_open_perms() helper used by all three call sites. Also normalizes the autodie throw pattern (all now use _maybe_throw_autodie). Closes cpan-authors#329 Closes cpan-authors#330 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
87b2ab4 to
abe174d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Extracts the permission-check block from
__open,_io_file_mock_open, and__sysopeninto a shared_check_open_perms()helper.Why
The block was copy-pasted three times with subtle divergences. In
__sysopen, theelsifbranch (parent-dir write+execute check for new file creation) was dead code: the ENOENT guard above it ensuredcontentswas always defined at that point. This meantsysopen(FH, $path, O_WRONLY|O_CREAT)in a restricted parent directory silently succeeded — while the equivalentopen()correctly returned EACCES.Closes #329 (dead elsif branch) and #330 (triple duplication).
How
$is_new = !defined $mock_file->{'contents'}before O_CREAT populates contents_check_open_perms($mock_file, $abs_path, $rw, $is_new, $func_name, @args)replaces all three blocks_maybe_throw_autodieTesting
t/perms.t: validates sysopen O_CREAT respects parent-dir permissions🤖 Generated with Claude Code
Quality Report
Changes: 9 files changed, 139 insertions(+), 1227 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline